/// <reference path="../global.d.ts" />

import renderBugCommon from './bug-common';
import renderBugList from './bug-list';
import renderBugDetail from './bug-detail';
import renderBugNew from './bug-new';
import renderBugAttachment from './bug-attachment';
import renderBugHistory from './bug-history';
import { assignToList } from '@components/assignToList.vue';
import { createShowHideBtn } from '@components/showHideFormItem.vue';
import { PathNameEnum } from '@enum/pathname.enum';
import { addStyle } from '@utils/addStyle';
import { addScriptRemote } from '@utils/addScript';
import style from '../style';
import { CDNScriptURLEnum } from '@enum/script.enum';
import { componentList } from '@components/componentList.vue';
import { versionList } from '@components/versionList.vue';
import { ccList } from '@components/ccList.vue';
import { newCCList } from '@components/newCCList.vue';
import { featureList } from '@components/featureList.vue';

const PATHNAME = window.location.pathname;

try {
  async function setup() {
    addStyle(style);

    await addScriptRemote(CDNScriptURLEnum.VUE);
    await addScriptRemote(CDNScriptURLEnum.NAIVE_UI);

    renderBugCommon();

    if (PATHNAME === PathNameEnum.BUG_LIST) {
      renderBugList();
    }

    if (PATHNAME === PathNameEnum.BUG_DETAIL) {
      renderBugDetail();

      assignToList();
      createShowHideBtn();
      newCCList();
      featureList();
      componentList();
      versionList();
    }

    if (PATHNAME === PathNameEnum.BUG_NEW) {
      renderBugNew();
      const component = document.querySelector('#component') as HTMLSelectElement;

      if (component) {
        componentList();
      }

      assignToList();
      versionList();
      featureList();
      ccList();
    }

    if (PATHNAME === PathNameEnum.BUG_ATTACHMENT) {
      renderBugAttachment();
    }

    if (PATHNAME === PathNameEnum.BUG_HISTORY) {
      renderBugHistory();
    }
  }

  setup();
} catch (error) {
  console.error(error);
}
